package com.ofek.eventos;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.google.gson.Gson;
import com.ofek.eventos.db.EventosDatabaseService;
import com.ofek.eventos.db.EventosDatabaseService.EventosDatabaseServiceBinder;
import com.ofek.eventos.db.EventosSyncService;
import com.ofek.eventos.db.datatypes.UserCredential;

public class ScriptActivity extends Activity implements ServiceConnection {
	private EventosDatabaseService eventosService;
	@Override
	protected void onCreate(final Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_script);
		//
		//		bindService(new Intent(this,EventosDatabaseService.class),this,Context.BIND_AUTO_CREATE);
		final Button button1 = (Button) findViewById(R.id.button1);
		button1.setText("login as htc@g.com");
		button1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(final View v) {
				EventosApplication.EVENTOS_USER = new UserCredential();
				EventosApplication.EVENTOS_USER.id = "htc@g.com";
				PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString(EventosApplication.KEY_USER, new Gson().toJson(EventosApplication.EVENTOS_USER)).commit();
				startActivity(new Intent(getApplicationContext(),EventosActivity.class));
				startService(new Intent(ScriptActivity.this,EventosDatabaseService.class));
				startService(new Intent(ScriptActivity.this,EventosSyncService.class));
			}
		});
		final Button button2 = (Button) findViewById(R.id.button2);
		button2.setText("login as pop@g.com");
		button2.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(final View v) {
				EventosApplication.EVENTOS_USER = new UserCredential();
				EventosApplication.EVENTOS_USER.id = "pop@g.com";

				PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString(EventosApplication.KEY_USER, new Gson().toJson(EventosApplication.EVENTOS_USER)).commit();

				startService(new Intent(ScriptActivity.this,EventosDatabaseService.class));
				startService(new Intent(ScriptActivity.this,EventosSyncService.class));
				startActivity(new Intent(getApplicationContext(),EventosActivity.class));
			}
		});
		final Button button3 = (Button) findViewById(R.id.button3);
		button3.setText("show archive");
		button3.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(final View v) {

				startService(new Intent(ScriptActivity.this,EventosDatabaseService.class));
				startService(new Intent(ScriptActivity.this,EventosSyncService.class));
				startActivity(new Intent(getApplicationContext(),ArchiveActivity.class));
			}
		});
	}
	@Override
	public void onServiceConnected(final ComponentName name, final IBinder service) {
		final EventosDatabaseServiceBinder binder = (EventosDatabaseServiceBinder) service;
	}
	@Override
	public void onServiceDisconnected(final ComponentName name) {
		// TODO Auto-generated method stub

	}
}
